home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_002 / cc / sprintfbug.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  36 lines

  1. /*
  2.  *    This program demonstrates that there is a limitation on how long
  3.  *    a string "sprintf()" is capable of printing.  On my machine, it
  4.  *    appears to be 200 characters.  I don't know whether this is the
  5.  *    limit on an individual argument, or the total of the argument
  6.  *    lengths, but it would be easy enough to write another test program
  7.  *    to find out.  So, beware..., this has already bitten me once.
  8.  *
  9.  *    Also, note that when the limit is reached, sprintf returns a value
  10.  *    one greater than the actual number of characters placed in the
  11.  *    output buffer.
  12.  *
  13.  *            Fred Fish
  14.  */
  15.  
  16. #include <stdio.h>
  17.  
  18. #define MAXSIZE (256)
  19.  
  20. main ()
  21. {
  22.     auto char buffer1[MAXSIZE+1];
  23.     auto char buffer2[MAXSIZE+1];
  24.     register int index;
  25.     register int xfered;
  26.  
  27.     buffer1[0] = 0;
  28.     buffer2[0] = 0;
  29.     for (index=0; index < MAXSIZE; index++) {
  30.     xfered = sprintf (buffer1, "%s%c", buffer2, '0' + (index % 10));
  31.     printf ("%3.3d: %s\n", xfered, buffer1);
  32.     fflush (stdout);
  33.     strcpy (buffer2, buffer1);
  34.     }
  35. }
  36.